package com.ssy.service.impl;

import com.ssy.entity.ClazzCountData;
import com.ssy.entity.JobOption;
import com.ssy.mapper.EmpMapper;
import com.ssy.mapper.StudentMapper;
import com.ssy.service.ReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class ReportServiceImpl implements ReportService {

    @Autowired
    private EmpMapper empMapper;
    @Autowired
    private StudentMapper studentMapper;

    /**
     * 统计员工职位人数
     * @return
     */
    @Override
    public JobOption getEmpJobData() {
        List<Map<String, Object>> list = empMapper.countEmpJobData();

        List<Object> jobList = list.stream().map(dataMap -> dataMap.get("pos")).toList();
        List<Object> dataList = list.stream().map(dataMap -> dataMap.get("num")).toList();

        return new JobOption(jobList, dataList);

    }

    /**
     * 统计员工性别人数
     * @return
     */
    @Override
    public List<Map<String, Object>> getEmpGenderData() {
        return empMapper.countEmpGenderData();
    }

    /**
     * 统计学生学历人数
     * @return
     */
    @Override
    public List<Map<String, Object>> getStudentDegreeData() {
        return studentMapper.countStudentDegreeData();
    }

    /**
     * 统计班级人数
     * @return
     */
    @Override
    public ClazzCountData getClazzData() {
        List<Map<String, Object>> list = studentMapper.countStudentByClazz();

        List<String> clazzList = list.stream()
                .map(dataMap -> (String) dataMap.get("clazzName"))
                .toList();

        List<Integer> dataList = list.stream()
                .map(dataMap -> {
                    Object count = dataMap.get("studentCount");
                    return count != null ? ((Number) count).intValue() : 0;
                })
                .toList();
        return new ClazzCountData(clazzList, dataList);
    }
}
